package com.sugon.controller.tool;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.ToolsFileEntity;
import com.sugon.service.ToolsFileService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 工装档案资料Controller
 *
 * @author sugon
 * @date 2019-08-05 09:24:58
 */
@Controller
@RequestMapping("toolsfile")
public class ToolsFileController {
    @Autowired
    private ToolsFileService toolsFileService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("toolsfile:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<ToolsFileEntity> toolsFileList = toolsFileService.queryList(query);
        int total = toolsFileService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(toolsFileList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("toolsfile:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        ToolsFileEntity toolsFile = toolsFileService.queryObject(id);

        return R.ok().put("toolsFile", toolsFile);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("toolsfile:save")
    @ResponseBody
    public R save(@RequestBody ToolsFileEntity toolsFile) {
        toolsFileService.save(toolsFile);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("toolsfile:update")
    @ResponseBody
    public R update(@RequestBody ToolsFileEntity toolsFile) {
        toolsFileService.update(toolsFile);

        return R.ok();
    }

    /**
     * ME工装/工艺工程师审核
     */
    @RequestMapping("/deptCheck")
    @RequiresPermissions("toolsfile:deptCheck")
    @ResponseBody
    public R deptCheck(@RequestBody ToolsFileEntity toolsFile) {
        toolsFileService.deptCheck(toolsFile);

        return R.ok();
    }

    /**
     * 领导审核
     */
    @RequestMapping("/leaderCheck")
    @RequiresPermissions("toolsfile:leaderCheck")
    @ResponseBody
    public R leaderCheck(@RequestBody ToolsFileEntity toolsFile) {
        toolsFileService.leaderCheck(toolsFile);

        return R.ok();
    }

    /**
     * 加入知识库
     * @param toolsFile
     * @return
     */
    @RequestMapping("/addKnowBase")
    @ResponseBody
    public R addKnowBase(@RequestBody ToolsFileEntity toolsFile) {
        toolsFileService.addKnowBase(toolsFile);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("toolsfile:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        toolsFileService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<ToolsFileEntity> list = toolsFileService.queryList(params);

        return R.ok().put("list", list);
    }
}
